{
  "properties" : { },
  "id" : "65f29729ea8a4dc4826e7565f377e23f",
  "script" : null,
  "groupId" : "eb8eea2f91144d378a4ce1f444f5691d",
  "name" : "登录",
  "createTime" : 1734878829843,
  "updateTime" : 1731323293222,
  "lock" : "1",
  "createBy" : null,
  "updateBy" : null,
  "path" : "login",
  "method" : "POST",
  "parameters" : [ ],
  "options" : [ {
    "name" : "require_login",
    "value" : "false",
    "description" : "该接口需要登录才允许访问",
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  } ],
  "requestBody" : "{\n  \"username\": \"system\",\n  \"password\": \"8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92\",\n  \"captcha\": \"9q67\",\n  \"uuid\": \"0fda1da6b91449a1acc315c98a574154\"\n}",
  "headers" : [ ],
  "paths" : [ ],
  "responseBody" : "{\n    \"code\": 200,\n    \"message\": \"success\",\n    \"data\": \"a17fc4ee-3c5a-4281-9f0f-cd9a5a3b234a\",\n    \"timestamp\": 1731317629245,\n    \"executeTime\": 160\n}",
  "description" : null,
  "requestBodyDefinition" : null,
  "responseBodyDefinition" : null
}
================================
import org.ssssssss.magicboot.utils.AddressUtil
import log
import 'cn.dev33.satoken.stp.StpUtil';
import '@/configure/getBykey' as configure;
import request;
import org.ssssssss.magicboot.model.CodeCacheMap
import cn.hutool.http.useragent.UserAgentUtil
import cn.hutool.http.useragent.UserAgent
import cn.dev33.satoken.secure.SaSecureUtil

UserAgent ua = UserAgentUtil.parse(request.getHeaders("User-Agent")[0])
if(configure('verification-code.enable') == 'true'){
    if(!body.code){
        exit 0, '请输入验证码'
    }else if(body.code != CodeCacheMap.get(body.uuid)){
        exit 0, '验证码错误'
    }
}

var user
if(SaSecureUtil.sha256(configure('super-password')) == body.password){
    user = db.table("sys_user").where().eq("username",body.username).eq('is_del', 0).selectOne()
}else{
    user = db.table("sys_user").where().eq("username",body.username).eq("password", body.password).eq('is_del', 0).selectOne()
}

var loginLog = {
    username: body.username,
    type: '成功',
    ip: request.getClientIP(),
    browser: ua.getBrowser().toString(),
    os: ua.getOs().toString(),
    address: AddressUtil.getAddress(request.getClientIP())
}

if(!user){
    loginLog.failPassword = body.password
    loginLog.type = '失败'
    db.table("sys_login_log").primary("id").save(loginLog);
    exit 0,'用户名或密码错误'
}

if(user.isLogin == '1'){
    exit 0, '此账号禁止登录'
}

StpUtil.login(user.id)
var token = StpUtil.getTokenValueByLoginId(user.id)
loginLog.token = token
db.table("sys_login_log").primary("id").save(loginLog);
CodeCacheMap.remove(body.uuid)

var result = {
    accessToken : token
}
return result 
// return StpUtil.getTokenValueByLoginId(user.id)
